#!/usr/bin/env node

/*eslint no-useless-escape: "error"*/

//引入文件系统
const fs = require('fs');

let data;
try {
    data = fs.readFileSync('./qr-code.jpg').toString('base64');
} catch (err) {
    console.error('Error reading file:', err);
    process.exit(1);
}

const uri = `data:image/jpg;base64,${data}`;
console.log('data uri:\n%s', uri);

const http = require('http');
// const svr = http.createServer();
// svr.on('request',(req, res) => {
//     res.end(`<!DOCTYPE html><html><body><img alt="nodejs-demo" src="${data}"></body></html>`);
// });
 // svr.listen(8080);

const html = '<!DOCTYPE html><html><body><img alt="nodejs-demo" src="' + uri + '"/></body</html>';
http.createServer(function(req,res) {
    console.log(req.headers);
    res.end(html);
}).listen(8080);
